package org.example.adapter.web;


import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import org.example.client.order.api.OrderServiceI;
import org.example.client.order.dto.clientobject.OrderCO;
import org.example.client.order.dto.cmd.OrderCreateCmd;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 订单相关
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderServiceI orderService;

    /**
     * 按订单编号查询
     */
    @GetMapping("/getByOrderNo")
    public SingleResponse<OrderCO> getByOrderNo(@RequestParam String orderNo) {
        return orderService.getByOrderNo(orderNo);
    }

    /**
     * 创建订单
     */
    @PostMapping("/createOrder")
    public Response createOrder(@Valid @RequestBody OrderCreateCmd orderCreateCmd) {
        return orderService.createOrder(orderCreateCmd);
    }
}
